package sketch.shape.geom;

import java.awt.Graphics2D;
import java.awt.geom.Line2D;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;

import sketch.shape.Shape;
import sketch.shape.geom.prim.Line;
import sketch.shape.geom.prim.Point;
import sketch.shape.geom.prim.gVector;

public class Rectangle extends Shape {

	Rectangle2D.Double rectangle;

	public Rectangle(double x, double y, double width, double height) {
		rectangle = new Rectangle2D.Double(x, y, width, height);
	}

	public Rectangle(java.awt.Rectangle bounds) {
		rectangle = new Rectangle2D.Double(bounds.x, bounds.y, bounds.width, bounds.height);
	}

	public Rectangle() {
		rectangle = new Rectangle2D.Double();
	}

	public Rectangle(Point refPoint, double width, double height) {
		this(refPoint.getX(), refPoint.getY(), width, height);
	}

	public boolean contains(double arg0, double arg1, double arg2, double arg3) {
		return rectangle.contains(arg0, arg1, arg2, arg3);
	}

	public boolean contains(double arg0, double arg1) {
		return rectangle.contains(arg0, arg1);
	}

	public boolean contains(Point2D arg0) {
		return rectangle.contains(arg0);
	}

	public boolean contains(Rectangle2D arg0) {
		return rectangle.contains(arg0);
	}

	public Rectangle2D createIntersection(Rectangle2D arg0) {
		return rectangle.createIntersection(arg0);
	}

	public Rectangle2D createUnion(Rectangle2D arg0) {
		return rectangle.createUnion(arg0);
	}

	public java.awt.Rectangle getBounds() {
		return rectangle.getBounds();
	}

	public Rectangle2D getBounds2D() {
		return rectangle.getBounds2D();
	}

	public double getCenterX() {
		return rectangle.getCenterX();
	}

	public double getCenterY() {
		return rectangle.getCenterY();
	}

	public double getHeight() {
		return rectangle.getHeight();
	}

	public double getMaxX() {
		return rectangle.getMaxX();
	}

	public double getMaxY() {
		return rectangle.getMaxY();
	}

	public double getMinX() {
		return rectangle.getMinX();
	}

	public double getMinY() {
		return rectangle.getMinY();
	}

	public double getWidth() {
		return rectangle.getWidth();
	}

	public Point getRefPoint() {
		return new Point(getX(), getY());
	}

	public double getX() {
		return rectangle.getX();
	}

	public double getY() {
		return rectangle.getY();
	}

	public boolean intersects(double arg0, double arg1, double arg2, double arg3) {
		return rectangle.intersects(arg0, arg1, arg2, arg3);
	}

	public boolean intersects(Rectangle2D arg0) {
		return rectangle.intersects(arg0);
	}

	public boolean intersectsLine(double arg0, double arg1, double arg2, double arg3) {
		return rectangle.intersectsLine(arg0, arg1, arg2, arg3);
	}

	public boolean intersectsLine(Line2D arg0) {
		return rectangle.intersectsLine(arg0);
	}

	public boolean isEmpty() {
		return rectangle.isEmpty();
	}

	public void setRect(double arg0, double arg1, double arg2, double arg3) {
		rectangle.setRect(arg0, arg1, arg2, arg3);
	}

	public void setRect(Rectangle2D arg0) {
		rectangle.setRect(arg0);
	}

	public void setRefPoint(Point p) {
		setRect(p.getX(), p.getY(), getWidth(), getHeight());
	}

	public void setWidth(double w) {
		setRect(getX(), getY(), w, getHeight());
	}

	public void setHeight(double h) {
		setRect(getX(), getY(), getWidth(), h);
	}

	public Rectangle2D toRectangle2D() {
		return new Rectangle2D.Double(rectangle.x, rectangle.y, rectangle.width, rectangle.height);
	}

	public void drawComponent(Graphics2D g2) {
		super.drawComponent(g2);
		g2.draw(rectangle);
	}

	public java.awt.Shape getBound(double GAP) {
		double x = getX() - GAP;
		double y = getY() - GAP;
		double width = getWidth() + 2 * GAP;
		double height = getHeight() + 2 * GAP;
		return new java.awt.geom.Rectangle2D.Double(x, y, width, height);
	}

	public String[][] getFieldValues() {
		return new String[][] {
				{"RefPoint", getRefPoint().toString()},
				{"Width", Double.toString(getWidth())},
				{"Height", Double.toString(getHeight())}
		};
	}

	public Point getCenter() {
		return new Point(getCenterX(), getCenterY());
	}

}
